package cs.ubbcluj.ro.tests;

import cs.ubbcluj.ro.datatypes.implementations.SparseMatrix;
import cs.ubbcluj.ro.datatypes.implementations.SparseVector;
import cs.ubbcluj.ro.linearsystem.implementations.LinearSystemLU;

public class InteriorPointMethodsTests {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		testLinearSystemSolver();
	}
	
	static void testLinearSystemSolver() {
		SparseMatrix A = new SparseMatrix(4, 4);
		
		// first row: 1 2 3 1
		A.addElement(0, 0, 1);
		A.addElement(0, 1, 2);
		A.addElement(0, 2, 3);
		A.addElement(0, 3, 1);
		
		// second row: 2 8 8 2
		A.addElement(1, 0, 2);
		A.addElement(1, 1, 8);
		A.addElement(1, 2, 8);
		A.addElement(1, 3, 2);
		
		// second row: 3 8 19 9
		A.addElement(2, 0, 3);
		A.addElement(2, 1, 8);
		A.addElement(2, 2, 19);
		A.addElement(2, 3, 9);

		// second row: 1 2 9 21
		A.addElement(3, 0, 1);
		A.addElement(3, 1, 2);
		A.addElement(3, 2, 9);
		A.addElement(3, 3, 21);
		
		SparseVector b = new SparseVector(4);
		b.addElement(0, 7);
		b.addElement(1, 20);
		b.addElement(2, 39);
		b.addElement(3, 33);
				
		try {
			LinearSystemLU linearSystem = new LinearSystemLU(A, b);
			SparseVector x = (SparseVector) linearSystem.solveSystem();
			
		    for (int i = 0; i < x.getNrOfRows(); i++) {
	    	    System.out.println(x.get(i));
	        }
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		
	}

}
